#! /bin/bash

function get_script_dir() {
    local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
    echo "${script_dir}"
}

NEOLIX_DIR=$(realpath "$(get_script_dir)/..")
NEOLIX_INSTALL_SCRIPT_DIR="${NEOLIX_DIR}/installation"
APOLLO_ROOT_DIR=$(realpath "${APOLLO_ROOT_DIR:-${NEOLIX_DIR}/../}")
APOLLO_SCRIPTS_DIR="${APOLLO_SCRIPTS_DIR:-${APOLLO_ROOT_DIR}/scripts/}"

function check_apollo() {
    if [ ! -d "${APOLLO_ROOT_DIR}/../apollo" ]; then
        echo "APOLLO_ROOT_DIR is not set. Please run \"git clone -b v9.0.0 https://gitee.com/ApolloAuto/apollo.git\" at "$(realpath "${APOLLO_ROOT_DIR}/..")" first."
        return 1
    fi
    return 0
}

function check_apollo_script(){
    if [ ! -e "${APOLLO_SCRIPTS_DIR}/apollo_base.sh" ]; then
        echo "Apollo scripts apollo_base.sh not found at ${APOLLO_SCRIPTS_DIR}"
        echo "Check if apollo is correctly cloned."
        return 1
    fi
    return 0
}

check_apollo
check_apollo_script
